package sg.edu.nus.iss.phoenix.radioprogram.delegate;

import sg.edu.nus.iss.phoenix.radioprogram.entity.RPSearchObject;
import sg.edu.nus.iss.phoenix.radioprogram.entity.RadioProgram;
import sg.edu.nus.iss.phoenix.radioprogram.service.RadioProgramService;

import java.util.ArrayList;

public class RPDelegate {

    /**
     * search program that matched Radio Program object
     *
     * @param rpso
     * @return List of programs that matched the search criteria
     */
    public ArrayList<RadioProgram> searchPrograms(RPSearchObject rpso) {
        RadioProgram rp = new RadioProgram(rpso.getName());
        rp.setDescription(rpso.getDescription());
        RadioProgramService service = new RadioProgramService();
        return service.searchPrograms(rp);
    }

    /**
     * search program that matched Radio Program object
     *
     * @param rpso
     * @return List of programs that matched the search criteria
     */
    public ArrayList<RadioProgram> findRPByCriteria(RPSearchObject rpso) {
        RadioProgram rp = new RadioProgram(rpso.getName());
        rp.setDescription(rpso.getDescription());
        RadioProgramService service = new RadioProgramService();
        return service.searchPrograms(rp);
    }

    /**
     * find program by name
     *
     * @param rpName
     * @return Radio Program object
     */
    public RadioProgram findRP(String rpName) {
        RadioProgram rp = new RadioProgram(rpName);
        RadioProgramService service = new RadioProgramService();
        return (service.searchPrograms(rp)).get(0);

    }

    /**
     * find all radio programs
     *
     * @return all radio programs
     */
    public ArrayList<RadioProgram> findAllRP() {
        RadioProgramService service = new RadioProgramService();
        return service.findAllRP();

    }

    /**
     * insert radio program object
     *
     * @param rp
     */
    public void insertRP(RadioProgram rp) {
        RadioProgramService service = new RadioProgramService();
        service.insertRP(rp);

    }

    /**
     * update radio program object
     *
     * @param rp
     */
    public void updateRP(RadioProgram rp) {
        RadioProgramService service = new RadioProgramService();
        service.updateRP(rp);

    }

    /**
     * delete radio program object
     *
     * @param rp
     */
    public void deleteRP(RadioProgram rp) {
        RadioProgramService service = new RadioProgramService();
        service.deleteRP(rp);
    }
}
